package cn.imvc.app.controllers.info;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Area;
import cn.imvc.app.models.AreaModel;
import cn.imvc.core.Render;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @author wujx
 * @time 2016年8月5日
 *
 */
public class AreaControllerImpl implements AreaController {
	private List<Area> provinces, citys, countrys;
	private int areaId;
	public int setValue;
	@Autowired
	private AreaModel areaModel;

	/**
	 * 获得省
	 * 
	 * @return
	 */
	public String getProvice() {
		provinces = areaModel.findAllProvinces();
		JSONArray jsonArray = new JSONArray();
		for (Area area : provinces) {
			JSONObject jObject = new JSONObject();
			jObject.put("id", area.getId());
			jObject.put("name", area.getName());
			jsonArray.add(jObject);

		}
		return Render.json(jsonArray.toString());
	}

	/**
	 * 获得当前省 下面的市
	 * 
	 * @return
	 */
	public String getCity() {
		citys = areaModel.findAllCitys(areaId);
		JSONArray jsonArray = new JSONArray();
		for (Area area : citys) {
			JSONObject jObject = new JSONObject();
			jObject.put("id", area.getId());
			jObject.put("name", area.getName());
			jsonArray.add(jObject);

		}
		return Render.json(jsonArray.toString());
	}

	/**
	 * 获取当前市 下面的县
	 */
	public String getCountry() {
		countrys = areaModel.findAllCountrys(areaId);
		JSONArray jsonArray = new JSONArray();
		for (Area area : countrys) {
			JSONObject jObject = new JSONObject();
			jObject.put("id", area.getId());
			jObject.put("name", area.getName());
			jsonArray.add(jObject);

		}
		return Render.json(jsonArray.toString());
	} 
	

	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		return "area/show";
	}

	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	public String create() {
		// TODO Auto-generated method stub
		return null;
	}

	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroyBatch() {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Area> getCitys() {
		return citys;
	}

	public void setCitys(List<Area> citys) {
		this.citys = citys;
	}

	public List<Area> getCountrys() {
		return countrys;
	}

	public void setCountrys(List<Area> countrys) {
		this.countrys = countrys;
	}

	public int getAreaId() {
		return areaId;
	}

	public void setAreaId(int areaId) {
		this.areaId = areaId;
	}

	public List<Area> getProvinces() {
		return provinces;
	}

	public void setProvinces(List<Area> provinces) {
		this.provinces = provinces;
	}

	public int getSetValue() {
		return setValue;
	}

	public void setSetValue(int setValue) {
		this.setValue = setValue;
	}
}
